package com.example.innovate.controller;

/*
    2021.9.13 update/
 */

import com.example.innovate.bean.Result;
import com.example.innovate.domain.NewFieldDO;
import com.example.innovate.service.NewFieldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/newField")
@Api(tags = "动态字段接口")
public class NewFieldController {
    @Autowired
    NewFieldService newFieldService;

    //@UserLoginToken
    @ApiOperation("添加新字段")
    @PostMapping("/addField")
    public Result addField(@RequestBody NewFieldDO newFieldDO) throws IOException {
        newFieldService.addField(newFieldDO);
        return new Result(200,"success","添加成功",null);
    }

    //@UserLoginToken
    @ApiOperation("删除新字段")
    @DeleteMapping("/deleteField")
    public Result deleteField(@RequestParam("id") int id) throws IOException {
        newFieldService.deleteField(id);
        return new Result(200,"success","删除成功",null);
    }

    //@UserLoginToken
    @ApiOperation("根据字段所属查找字段")
    @GetMapping("/findField")
    public Result findField(@RequestParam("surface") String surface) throws IOException {
        List<NewFieldDO> newFields = newFieldService.getFieldBySurface(surface);
        return new Result(200,"success","查找成功",newFields);
    }

    //@UserLoginToken
    @ApiOperation("修改新字段")
    @PostMapping("/updateField")
    public Result updateField(@RequestBody NewFieldDO newFieldDO) throws IOException {
        newFieldService.updateField(newFieldDO);
        return new Result(200,"success","修改成功",null);
    }
}
